package org.scohen.juploadr.uploadapi.zooomr;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public abstract class DefaultZooomrHandler extends DefaultHandler {

    protected String lastTag;
    protected String failureReason;
    protected int errorCode = 0;

    public DefaultZooomrHandler(Object parent) {
    }

    public void startElement(String uri, String localName, String qname,
            Attributes atts) throws SAXException {
        lastTag = qname;
        if ("err".equals(qname)) {
            failureReason = atts.getValue("msg");
            errorCode = Integer.parseInt(atts.getValue("code"));
        }
    }

    public boolean isSuccessful() {
        return failureReason == null;
    }

    public int getErrorCode() {
        return errorCode;
    }

    public String getFailureReason() {
        return failureReason;
    }

}
